package com.example.big_data.service.Impl;

import com.example.big_data.Mapper.Reader;
import com.example.big_data.bean.Product1;
import com.example.big_data.bean.Product2;
import com.example.big_data.bean.Sell;
import com.example.big_data.service.ISearchAllData;
import org.springframework.stereotype.Service;

import java.io.IOException;
import java.util.*;

@Service
public class SearchAllDataImpl implements ISearchAllData {

    Reader reader=new Reader();

    @Override
    public List<Product1> SearchAllProduct1() throws IOException {
        List<Product1> list=new ArrayList<>();

        List<String> lines=reader.read_forProduct1();

        for (String l:lines)
        {
            String s1=l.substring(1,5);
            String s2=l.substring(8,l.length()-1);
            String s3[]=new String[3];
            s3=s2.split(", ");

            int date =Integer.valueOf(s1);
            String kind=s3[0].substring(1,s3[0].length()-1);
            switch (kind){
                case "Furniture" :
                    kind="家具";
                    break;
                case "Office Supplies" :
                    kind="办公室用品";
                    break;
                case "Technology" :
                    kind="科技产品";
                    break;
            }


            int num=Integer.valueOf(s3[1]);
            double profit=Double.valueOf(s3[2]);

            Product1 product1 =new Product1(date,kind,num,profit);
            if(date==2018)
            list.add(product1);
        }

        return list;
    }

    @Override
    public List<Product2> SearchAllProduct2() throws IOException {
        List<Product2> list=new ArrayList<>();

        List<String> lines=reader.read_forProduct2();

        for (String l:lines)
        {

            String s1=l.substring(1,5);
            String s2=l.substring(8,l.length()-1);
            String s3[]=new String[3];
            s3=s2.split(", ");

            int date =Integer.valueOf(s1);
            String kind=s3[0].substring(1,s3[0].length()-1);

            switch (kind){
                case "Bookcases" :
                    kind="书架";
                    break;
                case "Chairs" :
                    kind="椅子";
                    break;
                case "Labels" :
                    kind="便签";
                    break;
                case "Tables" :
                    kind="桌子";
                    break;
                case "Storage" :
                    kind="存储柜";
                    break;
                case "Furnishings" :
                    kind="家具";
                    break;
                case "Art" :
                    kind="美术用具";
                    break;
                case "Phones" :
                    kind="仪器";
                    break;
                case "Binders" :
                    kind="粘胶";
                    break;
                case "Appliances" :
                    kind="电器";
                    break;
                case "Paper" :
                    kind="纸";
                    break;
                case "Accessories" :
                    kind="配饰";
                    break;
                case "Envelopes" :
                    kind="信封";
                    break;
                case "Fasteners" :
                    kind="扣件";
                    break;
                case "Supplies" :
                    kind="日用品";
                    break;
                case "Machines" :
                    kind="机器";
                    break;
                case "Copiers" :
                    kind="复印机";
                    break;
            }



            int num=Integer.valueOf(s3[1]);
            double profit=Double.valueOf(s3[2]);

            Product2 product2 =new Product2(date,kind,num,profit);
            if(date==2018)
            list.add(product2);
        }

        return list;
    }

    @Override
    public List<Sell> SearchAllSell() throws IOException {
        List<Sell> list=new ArrayList<>();

        List<String> lines=reader.read_forSell();

        for (String l:lines)
        {
            String s1=l.substring(1,5);
            String s2=l.substring(8,l.length()-1);
            String s3[]=new String[3];
            s3=s2.split(", ");

            int date =Integer.valueOf(s1);
            String area=s3[0].substring(1,s3[0].length()-1);
            switch (area){
                case "South" :
                    area="南方";
                    break;
                case "West" :
                    area="西方";
                    break;
                case "Central" :
                    area="中心";
                    break;
                case "East" :
                    area="东方";
                    break;
            }

            int num=Integer.valueOf(s3[1]);
            double profit=Double.valueOf(s3[2]);


            Sell sell=new Sell(date,area,num,profit);
            if(date==2018)
            list.add(sell);
        }

        return list;
    }
}
